<template>
  <div class="mobile-home-main-box">
    <div class="search-box">
      <Search :type="type" :setShowProData="setShowProData" />
    </div>
    <div>
      <PageFoot />
    </div>
    <div class="table-box">
      <ProjectList
        :tableData="showProData"
        :openInfoDrawer="openInfoDrawer"
        :activeName="activeName"
        :openCost="openCost"
        :openUpdate="openUpdate"
        :openAnnexAndMilestoner="openAnnexAndMilestoner"
        :openMilestoner="openMilestoner"
        :openAnnex="openAnnex"
        :openCollection="openCollection"
      />
    </div>
    <div class="drawer-box">
      <Drawer ref="infoDrawerRef" :drawer="drawer" :projectRow="projectRow" />
    </div>
    <div class="drawer-box">
      <CostDrawer
        ref="costDrawerRef"
        :drawer="drawer"
        :projectRow="projectRow"
      />
    </div>
    <div class="drawer-box">
      <UpdateDrawer
        ref="updataDrawerRef"
        :drawer="drawer"
        :projectRow="projectRow"
      />
    </div>
    <div class="drawer-box">
      <MilestonesDrawer
        ref="milestoneRef"
        :drawer="drawer"
        :projectRow="projectRow"
      />
    </div>
    <div class="drawer-box">
      <AnnexDrawer ref="annexRef" :drawer="drawer" :projectRow="projectRow" />
    </div>
  </div>
</template>


<script>
import PageHeader from "@/components/PageHeader.vue";
import Search from "@/components/Search.vue";
import Drawer from "./ui/Drawer.vue";
import CostDrawer from "./ui/CostDrawer.vue";
import UpdateDrawer from "./ui/UpdateDrawer.vue";
import MilestonesDrawer from "./ui/MilestonesDrawer.vue";
import AnnexDrawer from "./ui/AnnexDrawer.vue";
import ProjectList from "./ui/ProjectList.vue";

import {
  getStageProjectListApi,
  getAccessToken,
  getUser,
  getUserInfo,
} from "@/api/index";
import PageFoot from "@/components/PageFoot.vue";

import * as dd from "dingtalk-jsapi";
export default {
  components: {
    PageHeader,
    Search,
    Drawer,
    CostDrawer,
    UpdateDrawer,
    MilestonesDrawer,
    AnnexDrawer,
    PageFoot,
    ProjectList,
  },
  data() {
    return {
      // 项目列表
      type: "project",
      // 控制状态点高亮
      active: null,
      // 状态数组
      titleArr: [
        {
          proStage: "SalesResearch",
          stageName: "售前调研",
        },
        {
          proStage: "Develop",
          stageName: "研发阶段",
        },
        {
          proStage: "ElectricImplement",
          stageName: "电气实施",
        },
        {
          proStage: "Design",
          stageName: "产品设计",
        },
        {
          proStage: "DebugTogether",
          stageName: "联调阶段",
        },
        {
          proStage: "Waiting4Sign",
          stageName: "等待验收",
        },
        {
          proStage: "Finish",
          stageName: "已完成",
        },
      ],
      // 展示的项目源数据
      showProData: [],
      // 抽屉是否弹出
      drawer: false,
      // 当前点击的项目
      projectRow: null,
      activeName: "first",
      tableActive: 1,
      keyWord: "",
      startTime: "",
      endTime: "",
      options: [
        {
          value: "选项1",
          label: "正常",
        },
        {
          value: "选项2",
          label: "请假",
        },
        {
          value: "选项3",
          label: "旷工",
        },
        {
          value: "选项4",
          label: "出差",
        },
      ],
      value: "",
      options2: [
        {
          value: "选项1",
          label: "已同意",
        },
        {
          value: "选项2",
          label: "已驳回",
        },
        {
          value: "选项3",
          label: "审批中",
        },
      ],
      value2: "",
      // 钉钉个人信息
      code: "",
      accessToken: "",
      userId: {},
      userInfo: {},
      isPhone: false,
    };
  },
  watch: {
    showProData(nv, ov) {
      this.showProData.forEach((item, index) => {
        this.showProData[index].procity = item.proprovince + "-" + item.procity;
        let stageItem = this.titleArr.find((stageItem) => {
          return item.prostage === stageItem.proStage;
        });
        this.showProData[index].stageName = stageItem.stageName;
      });
    },
  },

  created() {
    this.getAllProjectData();
    // this.getIsPhone();
  },
  beforeDestroy() {
    // this.getDingAPI();
  },

  methods: {
    // // 获取是否为手机端
    // getIsPhone() {
    //   let info = navigator.userAgent;
    //   this.isPhone = /mobile/i.test(info);
    //   this.$store.commit("user/setUserIsPhone", this.isPhone);
    // },

    // // 链接钉钉Api,获取通行证
    // async getDingAPI() {
    //   if (dd.env.platform !== "notInDingTalk") {
    //     let _this = this;
    //     dd.ready(function () {
    //       dd.runtime.permission.requestAuthCode({
    //         corpId: "ding546527c2838da0e9",
    //         onSuccess: function (result) {
    //           _this.code = result.code;
    //         },
    //         onFail: function (err) {
    //           console.log("dd.onFail", err);
    //         },
    //       });
    //     });
    //     // 获取token
    //     let token = await getAccessToken({
    //       appKey: "dinguorjkehhr1mhx7ui",
    //       appSecret:
    //         "9wtjy6eKbt5zP-Qky3qtvWZ-rJ5odNCCCrAeKkrwzWmDLGxNtNyx5OJM937LzIz9",
    //     });
    //     this.accessToken = token.accessToken;
    //     this.onGetUser();
    //   }
    // },

    // // 获取用户id
    // async onGetUser() {
    //   let result = await getUser(
    //     {
    //       access_token: this.accessToken,
    //     },
    //     {
    //       code: this.code,
    //     }
    //   );
    //   this.userId = result.result;

    //   this.onGetUserInfo();
    // },

    // // 获取用户信息
    // async onGetUserInfo() {
    //   let result = await getUserInfo(
    //     {
    //       access_token: this.accessToken,
    //     },
    //     {
    //       userid: this.userId.userid,
    //       language: "zh_CN",
    //     }
    //   );
    //   // console.log('第四',result)
    //   this.userInfo = result.result;
    //   this.$store.commit("user/setDingUserData", this.userId);
    //   console.log("userInfo----->", result);
    //   this.$store.commit("user/setDingUserInfoData", this.userInfo);
    //   // let whiteResult = await ContainsPhoneNumber({
    //   //   phoneNumber: this.userInfo.mobile,
    //   // });
    //   // this.isWhiteUser = whiteResult.result;
    // },

    // 搜索赋值
    setShowProData(data) {
      this.showProData = data;
    },
    // 获取全部项目数据
    async getAllProjectData() {
      this.active = null;
      let res = await getStageProjectListApi();
      this.showProData = res;
    },
    // 阶段选择事件
    async selectItem(id) {
      this.active = id;
      let data = {
        prostage: this.titleArr[id].proStage,
      };
      let res = await getStageProjectListApi(data);
      this.showProData = res;
    },

    // 打开基本信息查看抽屉
    openInfoDrawer(row) {
      this.projectRow = { ...row };
      this.$refs.infoDrawerRef.openDrawer(row);
    },

    // 打开费用信息抽屉
    openCost(row) {
      this.projectRow = { ...row };
      this.$refs.costDrawerRef.openDrawer(row);
    },

    // 打开编辑基本信息抽屉
    openUpdate(row) {
      this.projectRow = { ...row };
      this.$refs.updataDrawerRef.openDrawer(row);
    },

    // 打开回款信息
    openCollection(row) {
      console.log("openCollection------>", row);
      this.projectRow = { ...row };
      this.$refs.collectionDrawerRef.openDrawer(row);
    },

    // 打开附件与里程碑抽屉
    openAnnexAndMilestoner(row) {
      this.projectRow = { ...row };
      this.$refs.milestoneRef.openDrawer(row);
    },

    openAnnex(row) {
      this.projectRow = { ...row };
      this.$refs.annexRef.openDrawer(row);
    },

    // 打开里程碑抽屉
    openMilestoner(row) {
      this.projectRow = { ...row };
      this.$refs.milestoneRef.openDrawer(row);
    },

    // 打开附件抽屉
    buttonClick(num) {
      console.log(num);
      this.tableActive = num;
    },
  },
};
</script>


<style lang="scss" >
.mobile-home-main-box {
  /* background: #f3f6ff; */
}
.search-box {
  /* border: 1px solid red; */
  width: 25%;
  margin-left: 10%;
  margin-top: 20px;
}

.test-step-box {
  /* border: 1px solid red; */
  width: 60%;
  margin-top: 10px;
  margin-left: 20%;
  display: flex;

  .test-step-item {
    /* border: 1px solid red; */
    height: 40px;
    width: 14%;
    line-height: 40px;
    text-align: center;
    color: #fff;
    background-image: url("../../assets/back-img3.png");
    background-size: 100% 100%;
  }
}

.table-box {
  /* border: 1px solid blue; */
  width: 80%;
  height: 450px;
  margin-left: 10%;
  margin-top: 10px;
  /* overflow: auto; */
}

.el-table {
  height: 450px;
}

.step-box {
  /* height: 50px; */
  width: 90%;
  margin-top: 10px;
  margin-left: 10%;
  /* border: 1px solid red; */
  display: flex;

  .step-item {
    width: 160px;
    height: 35px;
    line-height: 200%;
    display: flex;
    /* background: #f3f6ff; */

    .step-title {
      width: 70px;
      margin-right: 20px;
      color: black;
    }

    .icon {
      width: 30px;
    }
  }

  .step-item:hover {
    cursor: pointer;
  }
}

.head-step {
  /* border: 1px solid red; */
  display: flex;
  width: 600px;
  height: 40px;
  margin: 10px;
  margin-left: 150px;

  > div {
    border: 1px solid #aeb0b6;
    height: 40px;
    width: 150px;
    text-align: center;
    line-height: 40px;
    margin-right: 10px;
  }

  > div:hover {
    cursor: pointer;
    background: rgba($color: #aeb0b6, $alpha: 0.5);
  }
}

.screen-box {
  /* border: 1px solid red; */
  width: 80%;
  margin-left: 150px;

  > input {
    border: 1px solid #e4e6ec;
    height: 25px;
    margin-top: 5px;
    margin-right: 5px;
  }
}

.el-date-editor {
  margin-right: 5px;
}

.el-tabs__nav-scroll {
  /* border: 1px solid red; */
  width: 600px;
  margin-left: 150px;
}

@media screen and (max-width: 768px) {
  .mobile-home-main-box {
    background: none;
    /* border: 1px solid red; */
    height: 89vh;
    width: 99vw;
  }

  .page-btn {
    /* border: 1px solid blue; */
    height: 40px;
    margin-top: 10px;
    margin-left: 12px;
    width: 100%;
    line-height: 40px;
    display: flex;

    > div {
      border: 1px solid #dad2d2;
      margin: 0 5px;
      width: 20%;
      line-height: 20px;
      height: 20px;
      font-size: 12px;
      text-align: center;
    }

    > div:hover {
      cursor: pointer;
    }
  }

  .search-box {
    /* border: 1px solid red; */
    width: 100%;
    margin-left: 10px;
    margin-top: 10px;
    margin-bottom: 20px;
  }

  .test-step-box {
    /* border: 1px solid red; */
    width: 98%;
    margin-top: 10px;
    margin-left: 5px;
    display: flex;

    .test-step-item {
      /* border: 1px solid red; */
      height: 20px;
      width: 14%;
      font-size: 10px;
      line-height: 20px;
      text-align: center;
      color: #fff;
      background-image: url("../../assets/back-img3.png");
      background-size: 100% 100%;
    }
  }

  .table-box {
    /* border: 1px solid blue; */
    width: 98.5%;
    height: 520px;
    margin-left: 2px;
    margin-top: 10px;
    overflow: auto;
  }

  .step-box {
    /* height: 50px; */
    width: 90%;
    margin-top: 10px;
    margin-left: 10%;
    /* border: 1px solid red; */
    display: flex;

    .step-item {
      width: 160px;
      height: 35px;
      line-height: 200%;
      display: flex;
      /* background: #f3f6ff; */

      .step-title {
        width: 70px;
        margin-right: 20px;
        color: black;
      }

      .icon {
        width: 30px;
      }
    }

    .step-item:hover {
      cursor: pointer;
    }
  }

  .head-step {
    /* border: 1px solid red; */
    display: flex;
    width: 600px;
    height: 40px;
    margin: 10px;
    margin-left: 150px;

    > div {
      border: 1px solid #aeb0b6;
      height: 40px;
      width: 150px;
      text-align: center;
      line-height: 40px;
      margin-right: 10px;
    }

    > div:hover {
      cursor: pointer;
      background: rgba($color: #aeb0b6, $alpha: 0.5);
    }
  }

  .screen-box {
    /* border: 1px solid red; */
    width: 80%;
    margin-left: 150px;

    > input {
      border: 1px solid #e4e6ec;
      height: 25px;
      margin-top: 5px;
      margin-right: 5px;
    }
  }

  .el-date-editor {
    margin-right: 5px;
  }

  .el-tabs__nav-scroll {
    /* border: 1px solid red; */
    width: 600px;
    margin-left: 150px;
  }
}
</style>